//
//  RWBGetTime.m
//  Renwubang
//
//  Created by 张露杰 on 17/12/8.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "RWBGetTime.h"

@implementation RWBGetTime

+(NSString *)getTimeWithTimeString:(NSString *)timeString
{
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]/1000.0];
    NSTimeInterval timeInterval = [date timeIntervalSinceNow];
    timeInterval = -timeInterval;
    long temp = 0;
    NSString *result;
    if (timeInterval <= 60) {
        result = [NSString stringWithFormat:@"刚刚"];
    }else if((temp = timeInterval/60) < 60){
        result = [NSString stringWithFormat:@"%ld分钟前",temp];
    }else if((temp = timeInterval/3600) >= 1 && (temp = timeInterval/3600) <24){
        result = [NSString stringWithFormat:@"%ld小时前",temp];
    }else if ((temp = timeInterval/3600) >= 24 && (temp = timeInterval/3600) < 48){
        result = [NSString stringWithFormat:@"昨天"];
    }else if ((temp = timeInterval/3600) >= 48 && (temp = timeInterval/3600) < 72){
        result = [NSString stringWithFormat:@"前天"];
    }else{
        result = [TomamaUI dateTostiring:date andString:@"yyyy"];
        NSString *newYear = [TomamaUI dateTostiring:[TomamaUI getNowDate] andString:@"yyyy"];
        if ([result isEqualToString:newYear]) {
            result = [TomamaUI dateTostiring:date andString:@"MM.dd HH:mm"];
        }else{
           result = [TomamaUI dateTostiring:date andString:@"yyyy.MM.dd HH:mm"];
        }
    }
    return result;
}
@end
